<?php
/** search dvd Model class
*
* This is searching dvd class model to search for a movies or games depend on the input from the customer
*
* @author  Zoms
* @version 39
* @copyright copyright (c) 2011, Boston Univeristy Under BSD
* 
*/

class Model_search extends CI_Model {
    
 
    function search($search_field)
    {
            // The DB query to search 
            $query_str = "SELECT prod_id, p_name, menu_id, sku,
                p_description , p_price , p_tax , weight , p_images , p_type , options
                FROM `T_PRODUCTS` WHERE p_name LIKE ?";
            
            $search_results = $this->db->query($query_str, '%'.$search_field.'%');
            
            if($search_results->num_rows() > 0)
            {
                return $search_results->result_array();
            }
            else
            {
                return false;
            }
       
    }
    
    
    function search_special($search_field)
    {
            // The DB query to search for the movies 
            $query_str = "SELECT CC.order_id , CC.cus_id , CC.prod_id, CC.store_loc_id , C.cus_email , P.p_name , 
               CC.special_desc, CC.order_date FROM `T_CUS_CART` CC , `T_CUSTOMERS` C , `T_PRODUCTS` P WHERE CC.cus_id = C.cus_id and
               CC.prod_id = P.prod_id and CC.special_flag = 1 and CC.order_purch_flag = 0 and CC.status = 'Pending' and C.cus_username= ? ";
            
            // run the query with the required search input to get the results with movies titles that contains part of the search input
            $search_results = $this->db->query($query_str, $search_field);
            
            // check if the result contains more than one row of the DB query it will return array of the movies contains the search input  or  if less than or equal will return FALSE
            if($search_results->num_rows() > 0)
            {
                return $search_results->result();//->result_array();
            }
            else
            {
                 return array();
            }
       
    }
    
    
    function search_shipped_orders($search_field)
    {
            // The DB query to search for the movies 
            $query_str = "SELECT CC.order_id , CC.cus_id , CC.prod_id, CC.store_loc_id , C.cus_email  , p_name ,
               CC.special_desc, CC.order_date , status , shipped_on , payment_date FROM `T_CUS_CART_HIST` CC , `T_CUSTOMERS` C , `T_PRODUCTS` P WHERE CC.cus_id = C.cus_id and
               P.prod_id = CC.prod_id and CC.order_purch_flag = 1 and CC.status = 'Shipped' and C.cus_username= ? ";
            
            // run the query with the required search input to get the results with movies titles that contains part of the search input
            $search_results = $this->db->query($query_str, $search_field);
            
            // check if the result contains more than one row of the DB query it will return array of the movies contains the search input  or  if less than or equal will return FALSE
            if($search_results->num_rows() > 0)
            {
                return $search_results->result();//->result_array();
            }
            else
            {
                 return array();
            }
       
    }
    
    
    function search_customer_reservation($search_field)
    {
            // The DB query to search for the movies 
            $query_str = "SELECT CC.reserv_id , CC.cus_id , CC.spe_id, CC.store_loc , CC.special_desc ,  CC.reserv_date , reserv_time_start,
               CC.reserv_time_end, CC.has_been_resrved_flag , finished_date FROM `T_SPE_RESERV` CC , `T_CUSTOMERS` C WHERE CC.cus_id = C.cus_id and
               C.cus_username= ? ";
            
            // run the query with the required search input to get the results with movies titles that contains part of the search input
            $search_results = $this->db->query($query_str, $search_field);
            
            // check if the result contains more than one row of the DB query it will return array of the movies contains the search input  or  if less than or equal will return FALSE
            if($search_results->num_rows() > 0)
            {
                return $search_results->result();//->result_array();
            }
            else
            {
                 return array();
            }
       
    }
    function search_special_customer($cus_id)
    {
            // The DB query to search for the movies 
            $query_str = "SELECT CC.order_id , CC.cus_id , CC.prod_id, CC.store_loc_id , C.cus_email , P.p_name , 
               CC.special_desc, CC.order_date FROM `T_CUS_CART` CC , `T_CUSTOMERS` C , `T_PRODUCTS` P WHERE CC.cus_id = C.cus_id and
               CC.prod_id = P.prod_id and CC.special_flag = 1 and CC.order_purch_flag = 0 and CC.status = 'Pending' and C.cus_id= ? ";
            
            // run the query with the required search input to get the results with movies titles that contains part of the search input
            $search_results = $this->db->query($query_str, $cus_id);
            
            // check if the result contains more than one row of the DB query it will return array of the movies contains the search input  or  if less than or equal will return FALSE
            if($search_results->num_rows() > 0)
            {
                return $search_results->result();//->result_array();
            }
            else
            {
                 return array();
            }
       
    }
    
    
    function search_blocked()
    {
            // The DB query to search for the movies 
            $query_str = "SELECT reserv_id , S.cus_id , spe_id , store_loc , special_desc , reserv_date ,
                reserv_time_start , reserv_time_end , libility_amt , black_listed_date , C.cus_username ,
                C.CUS_EMAIL FROM `T_CUSTOMERS` C , `T_SPE_RESERV_HIS` S WHERE C.cus_id = S.cus_id 
                AND black_listed_date IS NOT NULL";
            
            // run the query with the required search input to get the results with movies titles that contains part of the search input
            $search_results = $this->db->query($query_str);
            
            // check if the result contains more than one row of the DB query it will return array of the movies contains the search input  or  if less than or equal will return FALSE
            if($search_results->num_rows() > 0)
            {
                return $search_results->result_array();
            }
            else
            {
                 return array();
            }
       
    }
    
    
    function search_customers_to_block()
    {
            // The DB query to search for the movies 
            $query_str = "SELECT reserv_id, S.cus_id , spe_id ,store_loc , special_desc , reserv_date,
                reserv_time_start , reserv_time_end , libility_amt , black_listed_date , C.cus_username ,
                C.CUS_EMAIL FROM `T_CUSTOMERS` C , `T_SPE_RESERV_HIS` S WHERE C.cus_id = S.cus_id 
                AND black_listed_date IS NULL";
            
            // run the query with the required search input to get the results with movies titles that contains part of the search input
            $search_results = $this->db->query($query_str);
            
            // check if the result contains more than one row of the DB query it will return array of the movies contains the search input  or  if less than or equal will return FALSE
            if($search_results->num_rows() > 0)
            {
                return $search_results->//result();//->
                result_array();
            }
            else
            {
                 return array();
            }
       
    }
    
}


?>